<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2019/11/13
 * Time: 9:46
 */

namespace app\index\controller;


use think\Db;

class Information extends Base
{
    /**
     * 联盟资讯列表页面展示
     * @return mixed
     */
    public function informationList(){
        $page = input('page')?input('page'):1;
        $information_type = input('information_type');
        $where['information_type'] = $information_type;
        $param = input('param.');
        if(isset($param['sheng'])){
            $sheng = $param['sheng'];
            $where['information_sheng_id'] = $param['sheng'];
        }else{
            $sheng = 0;
        }
        $list = Db::table('up_information')
            ->where($where)
            ->order('information_time desc')
            ->page($page, 12)
            ->select();
        foreach($list as $k => $v){
            if($v['information_num'] >= 1000){
                $list[$k]['information_num'] = number_format($v['information_num']/1000, 1) . 'k';
            }
        }
        // 地区
        $district = Db::table('up_sheng')->field('sheng_id, sheng_name')->select();
        $this->assign('list', $list);
        $this->assign('information_type', $information_type);
        $this->assign('district', $district);
        $this->assign('sheng', $sheng);
        return $this->fetch('information/informationlist');
    }
    
    /**
     * 更多政策解读---按钮显示
     * @return \think\response\Json
     */
    public function showMoreInformation(){
        $where['information_type'] = input('information_type');
        $sheng = input('sheng');
        if($sheng != 0){
            $where['information_sheng_id'] = $sheng;
        }
        $count = Db::table('up_information')->where($where)->count();
        return json(['status' => 200, 'count' => $count]);
    }
    
    /**
     * 更多政策解读
     * @return \think\response\Json
     */
    public function moreInformation(){
//        $d = Db::table('up_information')->select();
//        foreach ($d as $k=>$v){
//            unset($v['information_id']);
//            Db::table('up_information')->insert($v);
//        }
        $page = input('page');
        $where['information_type'] = input('information_type');
        $sheng = input('sheng');
        $keyword = input('keyword');
        if($sheng != 0){
            $where['information_sheng_id'] = $sheng;
        }
        if($keyword != ''){
            $where['information_title'] = ['like','%'.$keyword.'%'];
        }
        $data = Db::table('up_information')
            ->where($where)
            ->order('information_time desc')
            ->limit(($page-1)*12, 12)
            ->select();
        foreach($data as $k => $v){
            if($v['information_num'] >= 1000){
                $data[$k]['information_num'] = number_format($v['information_num']/1000, 1) . 'k';
            }
        }
        return json(['status' => 200, 'data' => $data]);
    }
}